package cn.wzptsoft.mall.controller;


import cn.wzptsoft.mall.pojo.dto.PageDto;
import cn.wzptsoft.mall.pojo.result.Result;
import cn.wzptsoft.mall.pojo.vo.PageVo;
import cn.wzptsoft.mall.pojo.vo.SpuDetailVo;

import cn.wzptsoft.mall.pojo.vo.SpuInfoVo;
import cn.wzptsoft.mall.service.ISpuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/spu")
@Slf4j
@Tag(name = "spu商品相关接口")
@RequiredArgsConstructor
public class SpuController {

    private final ISpuService iSpuService;

    @PostMapping("/all")
    @Operation(summary = "spu商品")
    public Result<List<SpuInfoVo>> allspu(){
        log.info("查找所有spu");
        List<SpuInfoVo> vo= iSpuService.getAll();
        return Result.ok(vo);
    }


    @PostMapping("/page")
    @Operation(summary = "spu商品分页")
    public Result<PageVo<SpuInfoVo>> pageSpu(@RequestBody PageDto pageDto){
        PageVo<SpuInfoVo> vo= iSpuService.pageSpu(pageDto);
        return Result.ok(vo);
    }

    @GetMapping("/detail/{id}")
    @Operation(summary = "spu详细商品")
    public Result<SpuDetailVo> getdetailSpu(@PathVariable Integer id){
        SpuDetailVo vo = iSpuService.getdetailSpu(id);
        return Result.ok(vo);
    }

    @GetMapping("/theme/{title}")
    @Operation(summary = "根据专题标题，查询spu商品")
    public Result<List<SpuInfoVo>> listSpuByThemeName(@PathVariable String title){
        List<SpuInfoVo> vo= iSpuService.listSpuByThemeName(title);
        return Result.ok(vo);
    }


}
